package com.yanqu.road.server.cmd.activity.shuihu;

import com.yanqu.road.pb.activity.ShuiHuActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.shuihu.ShuiHuModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SHUIHU_ACTIVITY_DRAW_CARD, desc = "抽卡")
public class ShuiHuDrawCardCmd extends AbstractCommand {

    private int itemNo;
    private int roundNo;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ShuiHuActivityProto.DrawCardReqMsg reqMsg = ShuiHuActivityProto.DrawCardReqMsg.parseFrom(packet.getBytes());
        itemNo = reqMsg.getItemNo();
        roundNo = reqMsg.getRoundNo();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ShuiHuModule shuiHuModule = player.getModule(ShuiHuModule.class);
        ret = shuiHuModule.drawCard(itemNo, roundNo);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ShuiHuActivityProto.DrawCardRespMsg.Builder builder = ShuiHuActivityProto.DrawCardRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SHUIHU_ACTIVITY_DRAW_CARD, builder);
        }
    }
}
